<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<%@ include file="../admin/top.jsp"%>
<link href="${ctx}/resource/css/form_table.css" rel="stylesheet" type="text/css" />

</head>
<body>
	<form action="" method="post">
		<input type="hidden" name="userId" value="${userId}">
		<input type="hidden" name="roleIds" id="roleIds">
	</form>
	<table id="ur_dg"></table>
	<script type="text/javascript">
	var roleIds = [];
	$(function(){
		$('#ur_dg').datagrid({    
			method: "POST",
			url:"${ctx}/role/user/listAuthorize?userId=${userId}",
		    fit : true,
			fitColumns : true,
			border : false,
			idField:"roleId",
			pagination:false,
			rownumbers:true,
			striped:true,
		    columns:[[    
				{field:'ck',checkbox:true}, 
				{
					field : 'code',
					title : '角色编码',
					sortable : true,
					width : 100
				}, {
					field : 'name',
					title : '角色名称',
					sortable : true,
					width : 100
				}, {
					field : 'remark',
					title : '描述',
					width : 200
				}
		    ]],
		    onLoadSuccess:function(data){
		    	if(data&&data.rows){
		    		for(var a=0;a<data.rows.length;a++){
		    			var d = data.rows[a];
		    			if(d.checked){
		    				roleIds.push(d.roleId);
		    				$('#ur_dg').datagrid("selectRecord",d.roleId)
		    			}
		    		}
		    	}
		    	$("#roleIds").val(roleIds.join(","));
		    	debugger;
		    },
		    onCheck:function(rowIndex,rowData){
		    	var ishas = false;
		    	if(roleIds){
		    		for(var a=0;a<roleIds.length;a++){
						if(roleIds[a]==rowData.roleId){
							ishas = true;
						}
					}
		    	}
		    	if(!ishas){
		    		roleIds.push(rowData.roleId);
			    	$("#roleIds").val(roleIds.join(","));
		    	}
		    	debugger;
		    },
		    onUncheck:function(rowIndex,rowData){
		    	if(roleIds){
		    		for(var a=0;a<roleIds.length;a++){
						if(roleIds[a]==rowData.roleId){
							roleIds.splice(a,1);
						}
					}
		    	}
		    	$("#roleIds").val(roleIds.join(","));
		    	debugger;
		    }
		});
	});
	</script>
</body>
</html>